import { LoadingUtil } from './../../common/loading';
import { BusiserviceProvider } from './../../providers/busiservice/busiservice';
import { UiserviceProvider } from './../../providers/uiservice/uiservice';
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, LoadingController } from 'ionic-angular';

/**
 * Generated class for the ProdPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-prod',
  templateUrl: 'prod.html',
})
export class ProdPage {
  loading:LoadingUtil;
  prodList:any=[];
  constructor(public navCtrl: NavController, public navParams: NavParams,
    public busiservice: BusiserviceProvider, private loadingCtrl: LoadingController, private uiservice: UiserviceProvider) {
      this.loading = new LoadingUtil(this.loadingCtrl);
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad ProdPage');
  }
  ionViewDidEnter(){
    this.getProdList();
  }
  getProdList(){
    this.loading.showLoading();
    this.busiservice.getProdList().subscribe(
      data => {
        if (data._success) {
          this.prodList = data.result;
          this.loading.hideLoading();
          //用户id
        } else {
          this.loading.hideLoading();
          this.uiservice.showAlert(data._message);
        }
      }
      ,
      error => {
        this.loading.hideLoading();
        this.uiservice.showAlert("网络异常!");
      }
    );
  }
  prodDetail(prod){
    this.navCtrl.push("ProddetailPage",{prod:prod});
  }
  addProd(){
    this.navCtrl.push("ProdaddPage");
  }
}
